package com.ktjiaotu;

import com.ktjiaotu.pojo.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;

/**
 * @Author: DABINGCHNEGJIAO
 * @CreateTime: 2025-06-03
 * @Description:
 * @Version: 1.0
 */
public class GetClassConstructorsInfo {
    public static void main(String[] args) {
        Constructor[] cons = Person.class.getDeclaredConstructors();
        System.out.println("=======构造方法展示=======");
        for (Constructor con : cons) {
            int modifiers = con.getModifiers();
            if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC) {
                System.out.println("访问修饰符是:public");
            } else if ((modifiers & Modifier.PROTECTED) == Modifier.PROTECTED) {
                System.out.println("<访问修饰符是>:protected");
            } else if ((modifiers & Modifier.PRIVATE) == Modifier.PRIVATE) {
                System.out.println("<访问修饰符是>:private");
            } else {
                System.out.println("访问修饰符是 default(package)");
            }
            Class[] parameterTypes = con.getParameterTypes();
            if (parameterTypes.length == 0) {
                System.out.println("该构造方法没有参数");
            } else {
                System.out.print("该构造方法的参数类型有: [");
                for (int i = 0; i < parameterTypes.length; i++) {
                    if (i != 0) {
                        System.out.print(",");
                    }
                    System.out.print(parameterTypes[i].getName());
                }
                System.out.println("]");
            }
            System.out.println("========================");
        }

    }
}
